/*
 * Mathe.cpp
 *
 *      Author: Christian
 *      Letztes Update: 03.11.13 | Code Aufräumen
 *
 */

#include "Mathe.h"

// Lookup-Table
const int16_t tan_list[] PROGMEM = {	0,		17,	   	35,	    52,		70,		87,		105,	126,	141,	158,  //0�  -> 9�
								176,	194,   	213,   	231,	249,	268,	288,	306,	325,	344,  //10� -> 19�
								364,	384,   	404,   	424,	445,	466,	488,	510,	532,	554,  //20� -> 29�
								577,	601,   	625,   	649,	675,	700,	727,	754,	781,	810,  //30� -> 39�
								839,	869,   	900,   	933,	966,   	1000,	1036,	1072,	1111,	1150, //40� -> 49�
								1192,	1235,	1280,	1327,	1376,	1428,	1483,	1540,	1600,	1664, //50� -> 29�
								1732,	1804,	1881,	1963,	2050,	2145,	2246,	2356,	2475,	2605, //60� -> 69�
								2747,	2904,	3078,	3271,	3487,	3732,	4011,	4331,	4705,	5145, //70� -> 79�
								5671,	6314,	7115,	8144,	9514,	11430,	14300,	19081,	28636,	32000, //80� -> 89�
								};



int8_t arctan_deg ( int16_t a , int16_t b ) {
	uint8_t i = 0;
	int32_t y = a * 100;
			y = y / ( b / 10 + 1 );
	int8_t vz = 1;

		if ( y < 0 ) {
			// Vorzeichen weg
				y *= -1;
				vz = -1;
		}

		for ( i = 1; i < 90; i++ ) {
			if ( ( int16_t ) pgm_read_word( &tan_list[i] ) >  y ) {
				break;
			}
		}
	//  den Kleineren Winkel waehlen
	return ( ( i - 1 )* vz );
}

uint16_t abs( int16_t value ) {
	if( value >= 0) {
		return (uint16_t)value;
	} else {
		return (uint16_t) (-1 * value);

	}
}
